//
//  ZShare.m
//  jipin
//
//  Created by lcb on 5/12/15.
//  Copyright (c) 2015 liuchengbin. All rights reserved.
//

#import "ZShare.h"
#import "OpenUDID.h"
#import <CommonCrypto/CommonDigest.h>  //MD5码转换

#import "SDWebImageManager.h"
#import "AnimationIndicator.h"
#import "viewconfig.h"
#import "BaseCell.h"
#import "UIImage+GIF.h"
#import "WTStatusBar.h"
#import "SVHTTPRequest.h"
#import "Zbase64.h"
@interface ZShare()
{
    
}
@property(nonatomic,strong)NSDictionary *shareDictionary;
@property(nonatomic,strong)NSString *addressInfoVer;
@end

@implementation ZShare
@synthesize imagesArray=_imagesArray;
@synthesize HotTagArray=_HotTagArray;
@synthesize IndexTagArray=_IndexTagArray;
@synthesize shareDictionary=_shareDictionary;
@synthesize searchParamsArray=_searchParamsArray;
@synthesize suggParamsArray=_suggParamsArray;
@synthesize lineCount=_lineCount;
@synthesize buyUrlArray=_buyUrlArray;
@synthesize addressInfoVer=_addressInfoVer;
@synthesize addressInfoDictionary=_addressInfoDictionary;
@synthesize defaultAddress=_defaultAddress;
@synthesize api_key=_api_key;
@synthesize hotmail=_hotmail;
@synthesize hotwords=_hotwords;
@synthesize zhekouquan=_zhekouquan;
@synthesize ipAddress=_ipAddress;
@synthesize sharecode_key=_sharecode_key;
@synthesize sharelist_key=_sharelist_key;

@synthesize menuList=_menuList;
@synthesize refreshHeader=_refreshHeader;
@synthesize refreshFooter=_refreshFooter;
@synthesize recommendChannel=_recommendChannel;
@synthesize subscribeChannel=_subscribeChannel;
@synthesize manuallySubscribe=_manuallySubscribe;
@synthesize sizeY=_sizeY;

+ (instancetype)sharedInstance
{
    static ZShare *instance;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [[ZShare alloc] init];
    });
    return instance;
}

- (id)init {
    self = [super init];
    if (self) {
        if (!_imagesArray) {
            _imagesArray =[[NSMutableArray alloc] init];
        }
        if (!_HotTagArray) {
            _HotTagArray =[[NSMutableArray alloc] init];
        }
        if (!_IndexTagArray) {
            _IndexTagArray = [[NSMutableArray alloc] init];
        }
        if (!_buyUrlArray) {
            _buyUrlArray = [[NSMutableArray alloc] init];
        }
        if (!_searchParamsArray) {
            _searchParamsArray =[[NSArray alloc] init];
        }
        if (!_suggParamsArray) {
            _suggParamsArray =[[NSMutableDictionary alloc] init];
        }
        if (!_addressInfoDictionary) {
            _addressInfoDictionary = [[NSMutableArray alloc] init];
        }
        if (!_hotwords) {
            _hotwords =[[NSMutableArray alloc] init];
        }
        if (!_hotmail) {
            _hotmail = [[NSMutableArray alloc] init];
        }
        if (!_menuList) {
            _menuList =[[NSMutableArray alloc] init];
        }
        if (!_sharelist_key) {
            _sharelist_key =[[NSMutableArray alloc] init];
        }
        if (!_recommendChannel) {
            _recommendChannel=[[NSMutableArray alloc] init];
        }
        if (!_subscribeChannel) {
            _subscribeChannel=[[NSMutableArray alloc] init];
        }
        if (!_manuallySubscribe) {
            _manuallySubscribe =[[NSMutableArray alloc] init];
        }
        _lineCount=2;
        _sizeY = 0;
    }
    return self;
}
-(void)dealloc
{
    self.imagesArray =nil;
    self.HotTagArray =nil;
    self.IndexTagArray=nil;
    self.buyUrlArray=nil;
    self.addressInfoDictionary=nil;
    self.addressInfoVer = nil;
    self.defaultAddress =nil;
    self.recommendChannel=nil;
    self.subscribeChannel=nil;
    self.manuallySubscribe=nil;
     DLog(@"%s", __PRETTY_FUNCTION__);
}

#pragma mark -
#pragma mark -----MD5码转换-----
+(NSString*)base64:(NSString*)str
{
    return __BASE64(str);
}
+ (NSString *)md5:(NSString *)_str{
    const char *_cStr = [_str UTF8String];
    unsigned char _result[16];
    CC_MD5( _cStr, strlen(_cStr), _result );
    return [NSString stringWithFormat:
            @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
            _result[0], _result[1], _result[2], _result[3],
            _result[4], _result[5], _result[6], _result[7],
            _result[8], _result[9], _result[10], _result[11],
            _result[12], _result[13], _result[14], _result[15]
            ];
}
//将NSDate按yyyy-MM-dd HH:mm:ss格式时间输出
+(NSString*)nsdateToString:(NSDate *)date{
    NSDateFormatter *dateFormat=[[NSDateFormatter alloc]init];
    [dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSString* string=[dateFormat stringFromDate:date];
    return string;
}

+(UIImage *) FICDSquareImageFromImage:(UIImage*)image {
    UIImage *squareImage = nil;
    CGSize imageSize = [image size];
    
    if (imageSize.width == imageSize.height) {
        squareImage = image;
    } else {
        // Compute square crop rect
        CGFloat smallerDimension = MIN(imageSize.width, imageSize.height);
        CGRect cropRect = CGRectMake(0, 0, smallerDimension, smallerDimension);
        
        // Center the crop rect either vertically or horizontally, depending on which dimension is smaller
        if (imageSize.width <= imageSize.height) {
            cropRect.origin = CGPointMake(0, rintf((imageSize.height - smallerDimension) / 2.0));
        } else {
            cropRect.origin = CGPointMake(rintf((imageSize.width - smallerDimension) / 2.0), 0);
        }
        
        CGImageRef croppedImageRef = CGImageCreateWithImageInRect([image CGImage], cropRect);
        squareImage = [UIImage imageWithCGImage:croppedImageRef];
        CGImageRelease(croppedImageRef);
    }
    
    return squareImage;
}
-(NSString* ) getUUID
{
    return [OpenUDID value];
}

-(NSString*)getUserNickname
{
    NSDictionary *user = [[NSUserDefaults standardUserDefaults] objectForKey:@"userinfo"];
    NSString * nickname = [user objectForKey:@"nick_name"];
    if (nickname==nil || nickname.length==0||[nickname isEqualToString:@"(null)"]) {
        nickname =@"";
    }
    nickname = [nickname stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    return nickname;
    
}

-(NSString*)getUserId
{
    NSDictionary *user = [[NSUserDefaults standardUserDefaults] objectForKey:@"userinfo"];
    NSString *userid = [user objectForKey:@"user_id"];
    if (userid==nil || userid.length==0||[userid isEqualToString:@"(null)"]) {
        userid =@"";
    }
    return userid;
}

-(NSString*)pushToken
{
    NSString *user = [[NSUserDefaults standardUserDefaults] objectForKey:@"pushToken"];
    if (user==nil || [user isEqualToString:@"(null)"]) {
        user =@"";
    }
    return user;
}
-(NSDictionary*)userInfo
{
    NSDictionary *user = [[NSUserDefaults standardUserDefaults] objectForKey:@"userinfo"];
    return user;
}
-(NSMutableArray *)IndexTagArray
{
    _IndexTagArray =[[NSUserDefaults standardUserDefaults] objectForKey:@"IndexTagArray"];
    return _IndexTagArray;
}
-(void)setIndexTagArray:(NSMutableArray *)IndexTagArray
{
    //将上述数据全部存储到NSUserDefaults中
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    //存储时，除NSNumber类型使用对应的类型意外，其他的都是使用setObject:forKey:
    [userDefaults setValue:IndexTagArray forKey:@"IndexTagArray"];
    //这里建议同步存储到磁盘中，但是不是必须的
    [userDefaults synchronize];
}
-(NSMutableArray *)buyUrlArray
{
    _buyUrlArray =[[NSUserDefaults standardUserDefaults] objectForKey:@"buyUrlArray"];
    return _buyUrlArray;
}
-(void)setBuyUrlArray:(NSMutableArray *)buyUrlArray
{
    //将上述数据全部存储到NSUserDefaults中
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    //存储时，除NSNumber类型使用对应的类型意外，其他的都是使用setObject:forKey:
    [userDefaults setValue:buyUrlArray forKey:@"buyUrlArray"];
    //这里建议同步存储到磁盘中，但是不是必须的
    [userDefaults synchronize];
}
-(NSMutableArray *)menuList
{
    _menuList =[[NSUserDefaults standardUserDefaults] objectForKey:@"menuList"];
    return _menuList;
}
-(void)setMenuList:(NSMutableArray *)menuList
{
    //将上述数据全部存储到NSUserDefaults中
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    //存储时，除NSNumber类型使用对应的类型意外，其他的都是使用setObject:forKey:
    [userDefaults setValue:menuList forKey:@"menuList"];
    //这里建议同步存储到磁盘中，但是不是必须的
    [userDefaults synchronize];
}

-(void)setUserInfo:(NSDictionary*)user
{
    //将上述数据全部存储到NSUserDefaults中
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    //存储时，除NSNumber类型使用对应的类型意外，其他的都是使用setObject:forKey:
    [userDefaults setValue:user forKey:@"userinfo"];
    //这里建议同步存储到磁盘中，但是不是必须的
    [userDefaults synchronize];
 
}
-(NSString*)sharecode_key
{
    _sharecode_key =[[NSUserDefaults standardUserDefaults] objectForKey:@"sharecode_key"];
    _sharecode_key =[[NSString stringWithFormat:@"%@",_sharecode_key] replaceNullString];
    return _sharecode_key;
}
-(void)setSharecode_key:(NSString *)sharecode_key
{
    //将上述数据全部存储到NSUserDefaults中
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    //存储时，除NSNumber类型使用对应的类型意外，其他的都是使用setObject:forKey:
    [userDefaults setValue:sharecode_key forKey:@"sharecode_key"];
    //这里建议同步存储到磁盘中，但是不是必须的
    [userDefaults synchronize];
}
-(NSMutableArray*)sharelist_key
{
    _sharelist_key =[[NSUserDefaults standardUserDefaults] objectForKey:@"sharelist_key"];
    return _sharelist_key;
}
-(void)setSharelist_key:(NSMutableArray *)sharelist_key
{
    //将上述数据全部存储到NSUserDefaults中
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    //存储时，除NSNumber类型使用对应的类型意外，其他的都是使用setObject:forKey:
    [userDefaults setValue:sharelist_key forKey:@"sharelist_key"];
    //这里建议同步存储到磁盘中，但是不是必须的
    [userDefaults synchronize];
}

-(NSString*)refreshHeader
{
    _refreshHeader =[[NSUserDefaults standardUserDefaults] objectForKey:@"refreshHeader"];
    _refreshHeader =[[NSString stringWithFormat:@"%@",_refreshHeader] replaceNullString];
    return _refreshHeader;
}
-(void)setRefreshHeader:(NSString *)refreshHeader
{
    //将上述数据全部存储到NSUserDefaults中
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    //存储时，除NSNumber类型使用对应的类型意外，其他的都是使用setObject:forKey:
    [userDefaults setValue:refreshHeader forKey:@"refreshHeader"];
    //这里建议同步存储到磁盘中，但是不是必须的
    [userDefaults synchronize];
}

-(NSString*)refreshFooter
{
    _refreshFooter =[[NSUserDefaults standardUserDefaults] objectForKey:@"refreshFooter"];
    _refreshFooter =[[NSString stringWithFormat:@"%@",_refreshFooter] replaceNullString];
    return _refreshFooter;
}
-(void)setRefreshFooter:(NSString *)refreshFooter
{
    //将上述数据全部存储到NSUserDefaults中
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    //存储时，除NSNumber类型使用对应的类型意外，其他的都是使用setObject:forKey:
    [userDefaults setValue:refreshFooter forKey:@"refreshFooter"];
    //这里建议同步存储到磁盘中，但是不是必须的
    [userDefaults synchronize];
}
-(NSMutableArray*)subscribeChannel
{
    _subscribeChannel =[[NSUserDefaults standardUserDefaults] objectForKey:@"subscribeChannel"];
    return _subscribeChannel;
}
-(void)setSubscribeChannel:(NSMutableArray *)subscribeChannel
{
    //将上述数据全部存储到NSUserDefaults中
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    //存储时，除NSNumber类型使用对应的类型意外，其他的都是使用setObject:forKey:
    [userDefaults setValue:subscribeChannel forKey:@"subscribeChannel"];
    //这里建议同步存储到磁盘中，但是不是必须的
    [userDefaults synchronize];
}
-(NSMutableArray*)recommendChannel
{
    _recommendChannel =[[NSUserDefaults standardUserDefaults] objectForKey:@"recommendChannel"];
    return _recommendChannel;
}
-(void)setRecommendChannel:(NSMutableArray *)recommendChannel
{
    //将上述数据全部存储到NSUserDefaults中
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    //存储时，除NSNumber类型使用对应的类型意外，其他的都是使用setObject:forKey:
    [userDefaults setValue:recommendChannel forKey:@"recommendChannel"];
    //这里建议同步存储到磁盘中，但是不是必须的
    [userDefaults synchronize];
}
-(NSMutableArray*)manuallySubscribe
{
    _manuallySubscribe =[[NSUserDefaults standardUserDefaults] objectForKey:@"manuallySubscribe"];
    return _manuallySubscribe;
}
-(void)setManuallySubscribe:(NSMutableArray *)manuallySubscribe
{
    //将上述数据全部存储到NSUserDefaults中
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    //存储时，除NSNumber类型使用对应的类型意外，其他的都是使用setObject:forKey:
    [userDefaults setValue:manuallySubscribe forKey:@"manuallySubscribe"];
    //这里建议同步存储到磁盘中，但是不是必须的
    [userDefaults synchronize];
}

-(NSString*)api_key
{
    _api_key =[[NSUserDefaults standardUserDefaults] objectForKey:@"api_key"];
    _api_key =[[NSString stringWithFormat:@"%@",_api_key] replaceNullString];
    return _api_key;
}
-(void)setApi_key:(NSString *)api_key
{
    //将上述数据全部存储到NSUserDefaults中
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    //存储时，除NSNumber类型使用对应的类型意外，其他的都是使用setObject:forKey:
    [userDefaults setValue:api_key forKey:@"api_key"];
    //这里建议同步存储到磁盘中，但是不是必须的
    [userDefaults synchronize];
}
-(void)initUserInfo:(NSDictionary*)resultObject
{
    NSString *api_key =[[NSString stringWithFormat:@"%@",[resultObject objectForKey:@"api_key"]] replaceNullString];
    if (api_key.length>0) {
        [self setApi_key:api_key];
    }
    NSString *share_code =[[NSString stringWithFormat:@"%@",[resultObject objectForKey:@"share_code"]] replaceNullString];
    if (share_code.length>0) {
        [self setSharecode_key:share_code];
    }
    id sharelist = [resultObject objectForKey:@"share_list"];
    if (sharelist && [sharelist isKindOfClass:[NSArray class]]) {
        NSMutableArray *temp = [NSMutableArray arrayWithArray:sharelist];
        if (temp.count>0) {
            [self setSharelist_key:temp];
            [[NSNotificationCenter defaultCenter] postNotificationName:@"shareToBuy" object:nil];
        }
        
    }
  
    NSString *user_email =[[NSString stringWithFormat:@"%@",[resultObject objectForKey:@"user_email"]] replaceNullString];
    NSString *user_id =[[NSString stringWithFormat:@"%@",[resultObject objectForKey:@"user_id"]] replaceNullString];
    NSString *user_type =[[NSString stringWithFormat:@"%@",[resultObject objectForKey:@"user_type"]] replaceNullString];
    NSString *nick_name =[[NSString stringWithFormat:@"%@",[resultObject objectForKey:@"nick_name"]] replaceNullString];
    NSString *user_phone =[[NSString stringWithFormat:@"%@",[resultObject objectForKey:@"user_phone"]] replaceNullString];
    NSString *largeFace =[[NSString stringWithFormat:@"%@",[resultObject objectForKey:@"largeFace"]] replaceNullString];
    NSString *middleFace =[[NSString stringWithFormat:@"%@",[resultObject objectForKey:@"middleFace"]] replaceNullString];
    NSString *smallFace =[[NSString stringWithFormat:@"%@",[resultObject objectForKey:@"smallFace"]] replaceNullString];
    
    NSString *check_in_days =[[NSString stringWithFormat:@"%@",[[resultObject objectForKey:@"user"] objectForKey:@"check_in_days"]] replaceNullString];
    NSString *fans_count =[[NSString stringWithFormat:@"%@",[[resultObject objectForKey:@"user"] objectForKey:@"fans_count"]] replaceNullString];
    NSString *follow_count =[[NSString stringWithFormat:@"%@",[[resultObject objectForKey:@"user"] objectForKey:@"follow_count"]] replaceNullString];
    NSString *user_level =[[NSString stringWithFormat:@"%@",[[resultObject objectForKey:@"user"] objectForKey:@"user_level"]] replaceNullString];
    NSString *user_score =[[NSString stringWithFormat:@"%@",[[resultObject objectForKey:@"user"] objectForKey:@"user_score"]] replaceNullString];
    NSString *user_balance =[[NSString stringWithFormat:@"%@",[[resultObject objectForKey:@"user"] objectForKey:@"user_balance"]] replaceNullString];
 
    
    NSDictionary *tmpDict =[NSDictionary dictionaryWithObjectsAndKeys:user_email,@"user_email",
                            @"",@"pwd",
                            user_id,@"user_id",
                            user_type,@"user_type",
                            nick_name,@"nick_name",
                            user_phone,@"user_phone",
                            largeFace,@"largeFace",
                            middleFace,@"middleFace",
                            smallFace,@"smallFace",
                            
                            check_in_days,@"check_in_days",
                            fans_count,@"fans_count",
                            follow_count,@"follow_count",
                            user_level,@"user_level",
                            user_score,@"user_score",
                            user_balance,@"user_balance",
                            api_key,@"api_key",
                            nil];
    [self setUserInfo:tmpDict];
}
-(NSString *)addressInfoVer
{
    _addressInfoVer =[[NSUserDefaults standardUserDefaults] objectForKey:@"addressInfoVer"];
    return _addressInfoVer;
}
-(void)setAddressInfoVer:(NSString *)addressInfoVer
{
    //将上述数据全部存储到NSUserDefaults中
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    //存储时，除NSNumber类型使用对应的类型意外，其他的都是使用setObject:forKey:
    [userDefaults setValue:addressInfoVer forKey:@"addressInfoVer"];
    //这里建议同步存储到磁盘中，但是不是必须的
    [userDefaults synchronize];
}
-(NSMutableArray *)addressInfoDictionary
{
    _addressInfoDictionary =[[NSUserDefaults standardUserDefaults] objectForKey:@"addressInfoDictionary"];
    if (_addressInfoDictionary==nil) {
         [self initaddress];
    }
    return _addressInfoDictionary;
}
-(void)setAddressInfoDictionary:(NSMutableArray *)addressInfoDictionary
{
    //将上述数据全部存储到NSUserDefaults中
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    //存储时，除NSNumber类型使用对应的类型意外，其他的都是使用setObject:forKey:
    [userDefaults setValue:addressInfoDictionary forKey:@"addressInfoDictionary"];
    //这里建议同步存储到磁盘中，但是不是必须的
    [userDefaults synchronize];
}
-(NSDictionary *)defaultAddress
{
    _defaultAddress =[[NSUserDefaults standardUserDefaults] objectForKey:@"defaultAddress"];
    return _defaultAddress;
}
-(void)setDefaultAddress:(NSDictionary *)defaultAddress
{
    //将上述数据全部存储到NSUserDefaults中
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    //存储时，除NSNumber类型使用对应的类型意外，其他的都是使用setObject:forKey:
    [userDefaults setValue:defaultAddress forKey:@"defaultAddress"];
    //这里建议同步存储到磁盘中，但是不是必须的
    [userDefaults synchronize];
}



-(NSString*)screenSize
{
    CGRect rect =[ UIScreen mainScreen ].applicationFrame;
    return NSStringFromCGRect(rect);
}
-(NSString*)osVer
{
    NSString *os_version = [[UIDevice currentDevice] systemVersion];
    return os_version;
}
-(NSString*)appVer
{
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
     NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
    return app_Version;
}
-(NSString*)systemModel
{
    NSString *model = [[UIDevice currentDevice] model];
    return model;
}
-(BOOL)isLogin
{
    NSString *userid = [self getUserId];
    if (userid && userid.length>0) {
        return YES;
    }
    return NO;
}
-(void)cleanCache
{
    @autoreleasepool {
        [[SDImageCache sharedImageCache] clearDisk];
        [[SDImageCache sharedImageCache] cleanDisk];
        [[SDImageCache sharedImageCache] clearMemory];//可有可无
    }
    
}
+(NSString*)DataTOjsonString:(id)object
{
    NSString *jsonString = nil;
    NSError *error;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:object
                                                       options:NSJSONWritingPrettyPrinted // Pass 0 if you don't care about the readability of the generated string
                                                         error:&error];
    if (! jsonData) {
        NSLog(@"Got an error: %@", error);
    } else {
        jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    }
    return jsonString;
}
+(void)showAnimationView:(UIView *)view center:(CGPoint)center
{
    
    if (view != nil) {
        
        UIView *v = [view viewWithTag:5047];
        if (v != nil) {
            return;
        }
        
        int x, y;
        if (center.x == CGPointZero.x || center.y == CGPointZero.y) {
            x = view.bounds.size.width / 2;
            y = view.bounds.size.height / 2;
        }
        else {
            x = center.x;
            y = center.y;
        }
        UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
        indicator.tag = 5047;
        indicator.center = CGPointMake(x, y);
        [view addSubview:indicator];
        if (!indicator.isAnimating) {
            [indicator startAnimating];
        }
        
    }
     //*/
}
+(void)hiddenAnimationView:(UIView *)view
{
    
    if (view != nil) {
        UIView *v = [view viewWithTag:5047];
        if (v != nil) {
            UIActivityIndicatorView *indicator =(UIActivityIndicatorView *)v;
            [indicator stopAnimating];
            [v removeFromSuperview];
            v=nil;
        }
    }
     //*/
}
+(void)hiddenAnimationView:(UIView *)view text:(NSString*)text
{
    
    if (view != nil) {
        UIView *v = [view viewWithTag:5047];
        if (v != nil) {
            [v removeFromSuperview];
            v=nil;
        }
    }
     //*/
}
+(void)showNoDataView:(UIView *)view center:(CGPoint)center
{
    if (view != nil) {
        
        UIView *v = [view viewWithTag:5048];
        if (v != nil) {
            return;
        }
        
        int x, y;
        if (center.x == CGPointZero.x || center.y == CGPointZero.y) {
            x = view.bounds.size.width / 2;
            y = view.bounds.size.height * 0.4f;
        }
        else {
            x = center.x;
            y = center.y;
        }
        UIImageView *wifiImageView =[[UIImageView alloc] initWithFrame:CGRectMake((view.frame.size.width-140)/2,(view.frame.size.height-140)/2,140, 140)];
        wifiImageView.center =CGPointMake(x, y);
        wifiImageView.image =[UIImage imageNamed:@"no_list_image.png"];
        wifiImageView.tag =5048;
        [view addSubview:wifiImageView];
        UILabel* Infolabel = [[UILabel alloc]initWithFrame:CGRectMake(0, wifiImageView.frame.origin.y+150, view.frame.size.width, 20)];
        Infolabel.backgroundColor = [UIColor clearColor];
        Infolabel.textAlignment = NSTextAlignmentCenter;
        Infolabel.textColor = UIColorFromRGB(0xcccccc);
        Infolabel.font = FONT(14);
        Infolabel.text =@"暂无榜单推荐";
        [view addSubview:Infolabel];
    }
}
+(void)showWifiView:(UIView *)view center:(CGPoint)center
{
    if (view != nil) {
        
        UIView *v = [view viewWithTag:5048];
        if (v != nil) {
            return;
        }
        
        int x, y;
        if (center.x == CGPointZero.x || center.y == CGPointZero.y) {
            x = view.bounds.size.width / 2;
            y = view.bounds.size.height * 0.4f;
        }
        else {
            x = center.x;
            y = center.y;
        }
        UIImageView *wifiImageView =[[UIImageView alloc] initWithFrame:CGRectMake((view.frame.size.width-180)/2,(view.frame.size.height-130)/2,180, 130)];
        wifiImageView.center =CGPointMake(x, y);
        wifiImageView.image =[UIImage imageNamed:@"wifi_no.png"];
        wifiImageView.tag =5048;
        [view addSubview:wifiImageView];
        wifiImageView=nil;
        UILabel* Infolabel = [[UILabel alloc]initWithFrame:CGRectMake(0, wifiImageView.frame.origin.y+150, view.frame.size.width, 20)];
        Infolabel.backgroundColor = [UIColor clearColor];
        Infolabel.textAlignment = NSTextAlignmentCenter;
        Infolabel.textColor = UIColorFromRGB(0xcccccc);
        Infolabel.font = FONT(14);
        Infolabel.text =@"亲，网络不给力哦!";
        [view addSubview:Infolabel];
        Infolabel=nil;
    }
}
+(void)hiddenWifiView:(UIView *)view
{
    if (view != nil) {
        UIView *v = [view viewWithTag:5048];
        if (v != nil) {
            [v removeFromSuperview];
            v=nil;
        }
    }
}
+ (void) moveUp: (UIView *)view andAnimationDuration: (float) duration andWait:(BOOL) wait andLength:(float) length{
    __block BOOL done = wait; //wait =  YES wait to finish animation
    [UIView animateWithDuration:duration animations:^{
        view.center = CGPointMake(view.center.x, view.center.y-length);
        
    } completion:^(BOOL finished) {
        done = NO;
    }];
    // wait for animation to finish
    while (done == YES)
        [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];
}

+ (void) moveDown: (UIView *)view andAnimationDuration: (float) duration andWait:(BOOL) wait andLength:(float) length{
    __block BOOL done = wait; //wait =  YES wait to finish animation
    [UIView animateWithDuration:duration animations:^{
        view.center = CGPointMake(view.center.x, view.center.y + length);
        
    } completion:^(BOOL finished) {
        done = NO;
    }];
    // wait for animation to finish
    while (done == YES)
        [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];
}
+ (UIView *) loadingView
{
    UIView *loading =[[UIView alloc] initWithFrame:CGRectMake(0, 0, DEVICE_WIDTH, PHOTO_FRAME_WIDTH*60)];
    loading.backgroundColor=[UIColor blackColor];
    UIActivityIndicatorView *activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    activityIndicatorView.hidesWhenStopped = YES;
    activityIndicatorView.center=loading.center;
    [loading addSubview:activityIndicatorView];
    [activityIndicatorView startAnimating];
    
    return loading;
}
-(NSArray *)searchParamsArray
{
    _searchParamsArray = [[NSUserDefaults standardUserDefaults] objectForKey:@"searchParamsArray"];
    return _searchParamsArray;
}
-(void)setSearchParamsArray:(NSArray *)searchParamsArray
{
    //将上述数据全部存储到NSUserDefaults中
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    //存储时，除NSNumber类型使用对应的类型意外，其他的都是使用setObject:forKey:
    [userDefaults setObject:searchParamsArray forKey:@"searchParamsArray"];
    //这里建议同步存储到磁盘中，但是不是必须的
    [userDefaults synchronize];
}
-(NSDictionary *)suggParamsArray
{
    _suggParamsArray =[[NSUserDefaults standardUserDefaults] objectForKey:@"suggParamsArray"];
    return _suggParamsArray;
}
-(void)setSuggParamsArray:(NSDictionary *)suggParamsArray
{
    //将上述数据全部存储到NSUserDefaults中
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    //存储时，除NSNumber类型使用对应的类型意外，其他的都是使用setObject:forKey:
    [userDefaults setObject:suggParamsArray forKey:@"suggParamsArray"];
    //这里建议同步存储到磁盘中，但是不是必须的
    [userDefaults synchronize];
}
+(NSMutableArray*)sortArray:(NSMutableArray*)tempArray
{
    [tempArray  sortUsingComparator:^NSComparisonResult(__strong id obj1,__strong id obj2){
        int sort = 0;
        int sort1 = 0;
        if ((obj1 && [obj1 isKindOfClass:[NSDictionary class]]) && (obj2 && [obj2 isKindOfClass:[NSDictionary class]])) {
            NSDictionary *dict =(NSDictionary *)obj1;
            NSDictionary *dict1 =(NSDictionary *)obj2;
          
            if (dict && [dict objectForKey:@"sort"]) {
                sort = [[dict objectForKey:@"sort"] intValue];
            }
            
            if (dict1 && [dict1 objectForKey:@"sort"]) {
                sort1 = [[dict1 objectForKey:@"sort"] intValue];
            }
        }
        return sort > sort1;
      
    }];
    return tempArray;
}
+(NSString*)publicParams
{
    NSString *params =@"&os=%@&appVer=%@&osVer=%@&partner=%@&uuid=%@&guest_id=%@&guest_name=%@&token=%@";
    NSString *strul =[NSString stringWithFormat:params,[ZShare sharedInstance].systemModel,[ZShare sharedInstance].appVer,[ZShare sharedInstance].osVer,@"appstore",[ZShare sharedInstance].getUUID,[[ZShare sharedInstance] getUserId],[[ZShare sharedInstance] getUserNickname],[[ZShare sharedInstance] pushToken]];
    strul = [strul stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    return strul;
}

//=======================================
//公共参数
//=======================================
-(void)initsearchparams
{
    NSString *urlstr = [NSString stringWithFormat:@"http://so.danpin.com/v2/searchParam.php?action=%@",[ZShare publicParams]];
    //给请求声称一个md5， 用于跟云端匹配，避免其他人请求我们的服务器。
    NSDate *  senddate=[NSDate date];
    NSDateFormatter  *dateformatter=[[NSDateFormatter alloc] init];
    [dateformatter setDateFormat:@"YYYYMMddhhmmss"];
    NSString *  strLocationTime=[dateformatter stringFromDate:senddate];
    //    NSLog(@"本机时间: %@",strLocationTime);
    
    NSString *ss =[NSString stringWithFormat:@"init_%@_little_hongyu_is_very_good_%@", strLocationTime, [ZShare sharedInstance].getUUID];
    NSString *strMD5 = [ZShare md5:ss];
   
    [[SVHTTPClient sharedClient] POST:urlstr parameters:
     [NSDictionary dictionaryWithObjectsAndKeys:
      //  strResult, @"data",
      strMD5, @"session",//加密后的md5
      strLocationTime, @"time", //时间明文必须传给服务器，服务器也声称md5进行比较
      nil]
                           completion:^(id response, NSHTTPURLResponse *urlResponse, NSError *error)
     {
         if (response==nil)
         {
             return;
         }
         if (error==nil)
         {
             NSDictionary *dc = [NSJSONSerialization JSONObjectWithData:response options:kNilOptions error:&error];
             if (dc && [dc isKindOfClass:[NSDictionary class]] )
             {
                 //更新公共参数
                 NSMutableArray *searcharray =[NSMutableArray array];
                 id relate = [dc objectForKey:@"relate"];
                 if (relate && [relate isKindOfClass:[NSArray class]])
                 {
                     [searcharray addObjectsFromArray:relate];
                 }
                 id search = [dc objectForKey:@"search"];
                 if (search && [search isKindOfClass:[NSArray class]])
                 {
                     [searcharray addObjectsFromArray:search];
                 }
                 [[ZShare sharedInstance] setSearchParamsArray:searcharray];
                 
                 NSDictionary* sugg = [dc objectForKey:@"sugg"];
                 if (sugg && [sugg isKindOfClass:[NSDictionary class]] && sugg.count > 0)
                 {
                     [[ZShare sharedInstance] setSuggParamsArray:sugg];
                 }
             }
         }
         
     }];
    
}
//=======================================
//danpin公共参数
//=======================================
-(void)initdanpinpublicparams:(NSString*)source
{
    //去购买的统计页面
    NSMutableDictionary *dicttt =[NSMutableDictionary dictionary];
    [dicttt setValue:@"indextab" forKey:@"action"];
    [dicttt setValue:@"" forKey:@"type"];
    [dicttt setValue:@"" forKey:@"can_buy"];
    [dicttt setValue:source forKey:@"source"];
    [BaseModel statbuypage:dicttt success:^(AFHTTPRequestOperation *operation, id result) {
        
    } failure:^(NSError *error) {
        
    }];
     __weak typeof (self) wSelf = self;
    [BaseModel publicList:nil success:^(AFHTTPRequestOperation *operation, id result) {
        if (result==nil) {
            return;
        }
        if (result && [result isKindOfClass:[NSDictionary class]]) {
            int  dp_good_new = [[result objectForKey:@"dp_good_new"] intValue];
            if (dp_good_new==1) {
                [[NSNotificationCenter defaultCenter] postNotificationName:@"updateHuobadge" object:nil];
            }
            
            int  have_new_ranking = [[result objectForKey:@"have_new_ranking"] intValue];
            if (have_new_ranking==1) {
                [[NSNotificationCenter defaultCenter] postNotificationName:@"updateRankbadge" object:nil];
            }
            int need_login = [[result objectForKey:@"need_login"] intValue];
            if (need_login==1) {
                [[ZShare sharedInstance] setUserInfo:nil];
            }
            id hotword =  [result objectForKey:@"hotwords"];
            if (hotword && [hotword isKindOfClass:[NSArray class]]){
                if ([hotword count]>0) {
                    [[ZShare sharedInstance].HotTagArray removeAllObjects];
                }
                for (id di in hotword) {
                    if (di && [di isKindOfClass:[NSString class]])
                    {
                        [[ZShare sharedInstance].HotTagArray addObject:di];
                    }
                }
            }
            id index_tab =  [result objectForKey:@"index_tab"];
            if (index_tab && [index_tab isKindOfClass:[NSArray class]]){
                [ZShare sharedInstance].IndexTagArray = index_tab;
            }
            
            id buy_url = [result objectForKey:@"buy_url"];
            if (buy_url && [buy_url isKindOfClass:[NSArray class]]){
                [ZShare sharedInstance].buyUrlArray = buy_url;
            }
            id user = [result objectForKey:@"user"];
            if (user && [user isKindOfClass:[NSDictionary class]])
            {
                NSString *user_email =[[NSString stringWithFormat:@"%@",[user objectForKey:@"user_email"]] replaceNullString];
                NSString *user_id =[[NSString stringWithFormat:@"%@",[user objectForKey:@"user_id"]] replaceNullString];
                NSString *user_type =[[NSString stringWithFormat:@"%@",[user objectForKey:@"user_type"]] replaceNullString];
                NSString *nick_name =[[NSString stringWithFormat:@"%@",[user objectForKey:@"nick_name"]] replaceNullString];
                NSString *user_phone =[[NSString stringWithFormat:@"%@",[user objectForKey:@"user_phone"]] replaceNullString];
                NSString *largeFace =[[NSString stringWithFormat:@"%@",[user objectForKey:@"largeFace"]] replaceNullString];
                NSString *middleFace =[[NSString stringWithFormat:@"%@",[user objectForKey:@"middleFace"]] replaceNullString];
                NSString *smallFace =[[NSString stringWithFormat:@"%@",[user objectForKey:@"smallFace"]] replaceNullString];
                
                NSString *check_in_days =[[NSString stringWithFormat:@"%@",[user objectForKey:@"check_in_days"]] replaceNullString];
                NSString *fans_count =[[NSString stringWithFormat:@"%@",[user objectForKey:@"fans_count"]] replaceNullString];
                NSString *follow_count =[[NSString stringWithFormat:@"%@",[user objectForKey:@"follow_count"]] replaceNullString];
                NSString *user_level =[[NSString stringWithFormat:@"%@",[user objectForKey:@"user_level"]] replaceNullString];
                NSString *user_score =[[NSString stringWithFormat:@"%@",[user objectForKey:@"user_score"]] replaceNullString];
                NSString *user_balance =[[NSString stringWithFormat:@"%@",[user objectForKey:@"user_balance"]] replaceNullString];
                
                NSDictionary *tmpDict =[NSDictionary dictionaryWithObjectsAndKeys:user_email,@"user_email",
                                        @"",@"pwd",
                                        user_id,@"user_id",
                                        user_type,@"user_type",
                                        nick_name,@"nick_name",
                                        user_phone,@"user_phone",
                                        largeFace,@"largeFace",
                                        middleFace,@"middleFace",
                                        smallFace,@"smallFace",
                                        
                                        check_in_days,@"check_in_days",
                                        fans_count,@"fans_count",
                                        follow_count,@"follow_count",
                                        user_level,@"user_level",
                                        user_score,@"user_score",
                                        user_balance,@"user_balance",
                                        nil];
                [[ZShare sharedInstance] setUserInfo:tmpDict];
            }
            NSString * addressInfoVer = [NSString stringWithFormat:@"%@",[result objectForKey:@"addressInfoVer"]];
            if( ![[ZShare sharedInstance].addressInfoVer isEqualToString:addressInfoVer])
            {
                [ZShare sharedInstance].addressInfoVer = addressInfoVer;
                [wSelf initaddress];
            }
        }
        
    } failure:^(NSError *error) {
        
    }];
}
-(void)initaddress
{
    [BaseModel getPctAllData:nil success:^(AFHTTPRequestOperation *operation, id result) {
        if (result && [result isKindOfClass:[NSArray class]]) {
            _addressInfoDictionary =result;
            [ZShare sharedInstance].addressInfoDictionary = result;
        }
    } failure:^(NSError *error) {
        
    }];
}
//========
+(UIView *)footerView:(NSString*)msg
{
    if (msg==nil || msg.length==0) {
        msg=@"单品 - 以一顶百";
    }
    UIView *footerview =[[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width,80)];
    footerview.backgroundColor=[UIColor clearColor];
    UILabel *footLabel =[[UILabel alloc] initWithFrame:CGRectMake(0, 30, [UIScreen mainScreen].bounds.size.width, 20)];
    footLabel.backgroundColor = [UIColor clearColor];
    footLabel.textColor = UIColorFromRGB(0xcccccc);
    footLabel.textAlignment = NSTextAlignmentCenter;
    footLabel.font = FONT(14);
    footLabel.text =msg;
    [footerview addSubview:footLabel];
    footLabel=nil;
    return footerview;
}

@end
